package com.cjjd.c.feature.home.hoteldevice;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.cjjd.c.R;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.utils.ScreenUtil;
import com.cjjd.c.utils.UIUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by dadagm on 17/9/8.
 */

public class PictureAdapter extends MyBaseAdapter {

    int w;
    public PictureAdapter(FragmentActivity mContext) {
        super(mContext);
        w = ScreenUtil.getScreenWidth(mContext) / 3;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewholder = null;
        if (convertView == null) {

            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_rooms, parent, false);
            viewholder = new ViewHolder(convertView);
            UIUtil.setRelativeLayoutParams2(convertView, RelativeLayout.LayoutParams.MATCH_PARENT, w*3/4 );

            convertView.setTag(viewholder);
        } else {
            viewholder = (ViewHolder)convertView.getTag();
        }


        PageBean bean = (PageBean) getItem(position);
        viewholder.img.setBackgroundResource(bean.id);
        viewholder.txt.setText(bean.name);
        if(bean.show){
            viewholder.dian.setVisibility(View.VISIBLE);
        }else{
            viewholder.dian.setVisibility(View.INVISIBLE);
        }

        return convertView;
    }

    public class ViewHolder {
        @Bind(R.id.img)
        ImageView img;
        @Bind(R.id.txt)
        TextView txt;
        @Bind(R.id.dian)
        ImageView dian;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
